package ro.prjmanager.web.actions.template;

import net.sourceforge.stripes.action.FileBean;
import ro.prjmanager.model.Template;
import ro.prjmanager.web.actions.NomenclatorAction;
import ro.prjmanager.web.annotation.Create;
import ro.prjmanager.web.annotation.Service;

import java.io.IOException;

@Service(target = "templateService")
@Create(resource = "/index.jsp",redirect = true)
public class TemplateAction extends NomenclatorAction<Template> {

   protected String name;
    protected FileBean vmFile;


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public FileBean getVmFile() {
        return vmFile;
    }

    public void setVmFile(FileBean vmFile) {
        this.vmFile = vmFile;
    }


    @SuppressWarnings({"ResultOfMethodCallIgnored"})
    protected Template castFromWeb() {
        Template ret = new Template();
        try {
            byte[] file = new byte[vmFile.getInputStream().available()];
            vmFile.getInputStream().read(file);
            ret.setName(getName());
            ret.setVmFile(file);

        } catch (IOException e) {
            log.error(e);
        }

       return ret;
    }

    protected void castFromModel(Template model) {

    }






}
